<?php

class Admin_bank extends CI_Controller {

    function __construct() {
        parent::__construct();
        if ($this->session->userdata('logged_in')) {
            $session_data = $this->session->userdata('logged_in');
            $data['username'] = $session_data['username'];
        } else {redirect('user_login/user', 'refresh');}
        
        $this->load->model('admin_bank_model');
        $this->load->model('user_role');
        $this->load->library('user_id');
        $this->load->helper('user_helper');
        
        if ($this->user_id->cek() == 0) {redirect('user_login/user', 'refresh');}
    }

    function index() {
        $data['id'] = $this->user_id->id();
        $data['i'] = 1;
        $data['access'] = $this->user_role->access($this->user_id->cek());
        $data['rows'] = $this->admin_bank_model->index();
        $data['content'] = 'admin_bank/index';
        $this->load->view('template/user', $data);
    }

    function add() {
        $data['id'] = $this->user_id->id();
        $data['access'] = $this->user_role->access($this->user_id->cek());
        $data['content'] = 'admin_bank/new';
        $this->load->view('template/user', $data);
    }

    function create() {
        $bank_name = $this->input->post('bank_name', TRUE);
        $an = $this->input->post('an', TRUE);
        $no_rekening = $this->input->post('no_rekening', TRUE);
        $this->admin_bank_model->create($bank_name, $an, $no_rekening);
    }

    function edit() {
        $data['id'] = $this->user_id->id();
        $id = $this->uri->segment(3);
        
        //cek
        $access = $this->user_role->access($this->user_id->cek());
        $this->user_role->chek($access, 'bank_edit');
        
        $data['access'] = $access; 
        $data['rows'] = $this->admin_bank_model->edit($id);
        $data['content'] = 'admin_bank/edit';
        $this->load->view('template/user', $data);
    }

    function update() {
        $id = $this->input->post('id', TRUE);
        $bank_name = $this->input->post('bank_name', TRUE);
        $an = $this->input->post('an', TRUE);
        $no_rekening = $this->input->post('no_rekening', TRUE);
        $this->admin_bank_model->update($id, $bank_name, $an, $no_rekening);
    }

    function delete() {
        $access = $this->user_role->access($this->user_id->cek());
        $this->user_role->chek($access, 'bank_delete');
        $id = $this->uri->segment(3);
        $this->admin_bank_model->delete($id);
    }

}

?>
